﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;

namespace thinger.MTHControlLib
{
    public partial class PanelEnhanced : Panel
    {
        public PanelEnhanced()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 用于绘制控件背景的事件处理方法
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            //取消绘制背景，解决闪烁
            //base.OnPaintBackground(e);//重载基类的背景
            return;
        }


        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            //设定双缓存
            this.DoubleBuffered = true;

            Graphics graphics = e.Graphics;

            if (this.BackgroundImage != null)
            {
                //消除锯齿
                graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

                graphics.DrawImage(this.BackgroundImage, new Rectangle(0, 0, this.Width, this.Height), new Rectangle(0, 0, this.BackgroundImage.Width, this.BackgroundImage.Height), GraphicsUnit.Pixel); ;
            }

        }
    }
}
